// 传入非 promise 对象，则返回成功的 promise 对象
// 传入参数为 promise 对象，参数的状态决定返回值的状态
// const p1 = Promise.resolve(112)
// const p2 = Promise.resolve(new Promise((resolve, reject) => {
//     // reject('error') // 失败
//     resolve('ok')
// }))

// // 不管传入什么类型参数，都是失败类型的 promise
// const p3 = Promise.reject(4)
// const p4 = Promise.reject(new Promise((resolve, reject) => {
//     resolve('ok')
// }))


const p11 = new Promise((resolve, reject) => {
    setTimeout(() => {
        let num = Math.random()
        if (num <= 0.5) {
            resolve(num)
        } else {
            reject(num)
        }
    }, 500)
})
const p12 = Promise.resolve(123)
const p13 = Promise.reject(321)
const p15 = Promise.reject(321)
const p14 = Promise.all([p11, p12])
p14.then(
    values => console.log('成功：', values),
    reasons => console.log('失败：', reasons)
)
const p16 = Promise.all([p11, p13,p15])
p16.then(
    values => console.log('成功：', values),
    reasons => console.log('失败：', reasons)
)


Promise.race([
    Promise.resolve('aaa'),
    Promise.reject('bbb'),
]).then(
    value => console.log(value),
    reason => console.log(reason)
)

Promise.race([
    Promise.reject('bbb'),
    Promise.resolve('aaa'),
]).then(
    value => console.log(value),
    reason => console.log(reason)
)